/*
 * urlCollection.cc
 *
 *  Created on: Apr 26, 2011
 *      Author: xrose
 */

#include "incdefault.h"
#include "urlCollection.h"
URLCollection::URLCollection(){
	_size = 0;
	_cap = 20;
	_rec = new char*[_cap];
	for(int i=0; i<_cap; i++){
		_rec[i]=new char[MAX_STR_LEN];
	}
}
URLCollection::URLCollection(int cap){
	_cap=cap;
	_rec=new char* [_cap];
	_size=0;
	for(int i=0; i<_cap; i++){
		_rec[i]=new char[MAX_STR_LEN];
	}
}
URLCollection::URLCollection(const URLCollection &url){
	_size=url._size;
	_cap=url._cap;
	_rec=new char*[_cap];
	for(int i=0; i<_cap; i++){
		_rec[i]=new char[MAX_STR_LEN];
		strcpy(_rec[i], url._rec[i]);
	}
}
URLCollection::~URLCollection(){};
int URLCollection::getsize(){
	return _size;
}
void URLCollection::put(string url){
	if(isUrlExist(url)) return;
	strcpy(_rec[_size], url.c_str());
	_size++;
}
char* URLCollection::get(int pos){
	if(pos<_size){
		return _rec[pos];
	}
	return NULL;
}
bool URLCollection::isUrlExist(string url){
	for(int i=0; i<_size; i++){
		if(strcasecmp(url.c_str(), _rec[i])==0) return true;
	}
	return false;
}
